#include "client.h"
#include "ui_client.h"

client::client(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::client)
{
    ui->setupUi(this);
    setWindowTitle("接收端");
    m_udpThread = new udpthread(this);

    connect(m_udpThread,SIGNAL(sigRecvOk(char*,int)),this,SLOT(slotRecv_client(char*,int)));
    m_udpThread->start();
    qDebug("OK");
}

client::~client()
{
    delete ui;
}

void client::slotRecv_client(char *buf, int len){
    file.setFileName("接受文件.pdf");
    filesize = len;
    file.resize(filesize);

    bool isOK = file.open(QIODevice::WriteOnly);

    qDebug()<<isOK;
    qint64 write_len = file.write(buf,len);

    qDebug()<<"client:写入文件的大小"<<write_len;
    qDebug()<<"filesize="<<len;

    QPixmap pixmap;
    pixmap.loadFromData((uchar*)buf,len,"txt");
    ui->label->setText("接受成功");
    file.close();
}
